package com.lenovo.leos.letools;

import java.util.Map;


import android.test.AndroidTestCase;
import android.util.Log;

import com.lenovo.leos.letools.lenovodata.BaseNetClientServer;
import com.lenovo.leos.letools.utils.ListFileUseParams;

/**
 * junit test
 * 
 * @author cys
 */
public class TestBaseNetClientServer extends AndroidTestCase {

	private BaseNetClientServer ncs;

	public TestBaseNetClientServer() {
		this.ncs = new BaseNetClientServer();
	}

	//{"result":1,"name":"ccyyss","filesize":1024,"dirid":"1301279145610203981","status":"4","issubaccount":0}
	//{“result”:0,”errmsg”:”用户不存在”}
	public void testLogin() throws Exception {
		String retval = ncs.login(this.getContext(), "cys1982_6_28@sina.com","123456");
		Log.i("return", "=========="+retval);
//		JSONObject obj = new JSONObject(retval);
//		String errorInf = obj.getString("errmsg");
//		URLEncoder.encode(errorInf);//将编码解析成字符
//		Log.i("return", "=========="+errorInf);
	}
	
	//{"result":1,"totalspace":"10737418240","space":"41232954"}
	public void testGetSpace() throws Exception {
		Log.i("return", "==========" + ncs.getSpace(this.getContext()));
	}

	//{"result":1,"id":"1302080563910209440","rootid":"1302080563910209440","type":"folder","privilege":"1111111111111111"}
	public void testCreateDir() throws Exception {
		Log
				.i("return", "==========="
						+ ncs.createDir(this.getContext(),
								"1302575984307201770", "bb"));
	}
	//{"result":1,"list":[{"dirid":"1301637937084203524","dirname":"aaa","privilege":"65535","ownername":"","isshare":"0"}],"files":4}
	//{"result":1,"list":[],"files":4}
	public void testListDir() throws Exception {
		Log.i("return", "============"
				+ ncs.listDir(this.getContext(), "1302575984307201770"));
	}

	public void testdelDir() throws Exception {
		Log.i("return", "============"
				+ ncs.delDir(this.getContext(), "1302511773557200420"));
	}

	public void testrenameDir() throws Exception {
		Log
				.i("return", "==========="
						+ ncs.renameDir(this.getContext(),
								"1302511773557200420", "cc"));
	}

	public void testmoveDir() throws Exception {
		Log.i("return", "==========="
				+ ncs.moveDir(this.getContext(), "1300558808072208870",
						"1300189532251205686"));
	}
	//filepath:/mnt/sdcard/parentDir2/son2/hongchen.jpg  parentdirid:1302414694760205187

	public void testListFile() throws Exception {
		ListFileUseParams lfp = new ListFileUseParams();
		lfp.dirid = "1302774645861202421";
		Log.i("return", "===========" + ncs.listFile(this.getContext(), lfp));
	}

	public void testdelFile() throws Exception {
		Log.i("return", "==========="
				+ ncs.deleteFile(this.getContext(), "1300446762547200350"));
	}

	public void testrenameFile() throws Exception {
		Log.i("return", "==========="
				+ ncs.renameFile(this.getContext(), "1300190792312206019",
						"fff.jpg"));
	}

	public void testmoveFile() throws Exception {
		Log.i("return", "==========="
				+ ncs.moveFile(this.getContext(), "1299811315726200757",
						"1300190792312206019", "1"));
	}

	public void testpredownload() throws Exception {
//		BaseNetClientServer.DownloadCookie result = ncs.predownload(this
//				.getContext(), "1300190792312206019");
//		Log.i("return", "==============" + result.getJsonVal());
//		Log.i("return", "==============" + result.getCookie_filename());
//		Log.i("return", "==============" + result.getCookie_ta());
		ncs.predownload(this.getContext(),"1302491768434205600");
	}

	public void testpreupload(){
		try{
			Map<String,String> map = ncs.preupload(this.getContext(), "1301279145610203981",
					"qqqw.txt", 1024 + "", "344", "0");
			Log.i("retval","================="+map.get("jsonVal"));
			Log.i("cookie_token","================="+map.get("cookie_token"));
		}catch(Exception e){
			Log.i("error","================="+e.getMessage());
		}
	}
}
